// pages/myCards/myCards.js  
var app = getApp();
Page({

  /**
   * 页面的初始数据 
   */
  data: {
    cards: [],
    page: 1
  },
  tocard: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.redirectTo({
      url: '/pages/index/index?card_id='+id,
    })
  },
  onLoad: function(options) {
    var that = this;
    app.httpRequest('card.card/lists', {}, 'get', true, function(res){
      that.setData({
        selfCard: res.data.selfCard,
        list: res.data.list.data,
        enterprise: res.data.enterprise,
        pageShow: true,
        page: ++that.data.page
      })
      app.userBehavior(111,'查看了名片夹')
    })
  },
  toindex:function(){
    wx.navigateTo({
      url: '/pages/index/index',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    console.log('onReachBottom')
    var that = this;
    if(that.data.dataFinish) return;
    var page = that.data.page;
    app.httpRequest('card.card/lists', {page: page}, 'get', true, function(res){
      if(res.data.list.data.length < 1){
        that.setData({
          dataFinish: true,
        })
      }else{
        that.setData({
          list: that.data.list.concat(res.data.list.data),
          page: ++that.data.page
        })
      }
    })
  },
})